package com.smartleanx.module.hrm.service.examine.examineDimension;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.smartleanx.module.hrm.controller.admin.examine.examineDimension.vo.*;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineDimension.ExamineDimensionDO;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.common.pojo.PageParam;
import com.smartleanx.framework.common.util.object.BeanUtils;

import com.smartleanx.module.hrm.dal.mysql.examine.examineDimension.ExamineDimensionMapper;

import static com.smartleanx.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.smartleanx.module.hrm.enums.ErrorCodeConstants.*;

/**
 * 考核维度 Service 实现类
 *
 * @author 
 */
@Service
@Validated
public class ExamineDimensionServiceImpl implements ExamineDimensionService {

    @Resource
    private ExamineDimensionMapper examineDimensionMapper;

    @Override
    public Integer createExamineDimension(ExamineDimensionSaveReqVO createReqVO) {
        // 插入
        ExamineDimensionDO examineDimension = BeanUtils.toBean(createReqVO, ExamineDimensionDO.class);
        examineDimensionMapper.insert(examineDimension);
        // 返回
        return examineDimension.getId();
    }

    @Override
    public void updateExamineDimension(ExamineDimensionSaveReqVO updateReqVO) {
        // 校验存在
        validateExamineDimensionExists(updateReqVO.getId());
        // 更新
        ExamineDimensionDO updateObj = BeanUtils.toBean(updateReqVO, ExamineDimensionDO.class);
        examineDimensionMapper.updateById(updateObj);
    }

    @Override
    public void deleteExamineDimension(Integer id) {
        // 校验存在
        validateExamineDimensionExists(id);
        // 删除
        examineDimensionMapper.deleteById(id);
    }

    private void validateExamineDimensionExists(Integer id) {
        if (examineDimensionMapper.selectById(id) == null) {
            throw exception(EXAMINE_DIMENSION_NOT_EXISTS);
        }
    }

    @Override
    public ExamineDimensionDO getExamineDimension(Integer id) {
        return examineDimensionMapper.selectById(id);
    }

    @Override
    public PageResult<ExamineDimensionDO> getExamineDimensionPage(ExamineDimensionPageReqVO pageReqVO) {
        return examineDimensionMapper.selectPage(pageReqVO);
    }

}